from flask import Blueprint, request, jsonify
import logging, os
from utils import common
captcha_bp = Blueprint('captcha', __name__, url_prefix='/captcha')


# modules_and_functions = common.find_modules_and_functions(os.path.dirname(__file__))

# for module, impls in modules_and_functions:
#     for impl in impls:
#         admin_bp.add_url_rule(f"{module.__name__}/{impl if impl.find('_') == -1  else '/'.join(impl.split('_'))}", impl, getattr(module, impl))



@captcha_bp.route('/get', methods=['GET'])
def get_captcha():
    body, thumb, dots = common.generate_captcha_image()
    return jsonify({'code':0, 'data':{'image':body, 'thumb':thumb, 'key':dots}})


@captcha_bp.route('/check', methods=['POST'])
def check_captcha():
    ## TODO
    #校验人机，发送验证码
    return jsonify({'code':0})

@captcha_bp.record
def log(app):
    logging.info('register captcha blueprint')
